/*
* 所谓“深拷贝，就是将其中所有的东西都拷贝一遍”
* */
class Score implements Cloneable{
    double S = 98.6;

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }
}
class Student implements Cloneable{
    String name;
    Score score = new Score();

    @Override
    protected Object clone() throws CloneNotSupportedException {
        Student student = (Student) super.clone();//对student对象进行拷贝
        student.score = (Score)this.score.clone();//对student对象中的成员进行拷贝
        return student;
    }
}
public class Test {
    public static void main(String[] args) throws CloneNotSupportedException{
        Student student1 = new Student();
        Student student2 = (Student) student1.clone();
        System.out.println(student1.score.S);
        System.out.println(student2.score.S);
        System.out.println("================");
        student2.score.S = 87.3;
        System.out.println(student1.score.S);
        System.out.println(student2.score.S);
    }
    public static void main2(String[] args) throws CloneNotSupportedException{
        Student student1 = new Student();
        Student student2 = (Student) student1.clone();
        System.out.println(student1.score.S);
        System.out.println(student2.score.S);
        System.out.println("================");
        student2.score.S = 87.3;
        System.out.println(student1.score.S);
        System.out.println(student2.score.S);
    }
    public static void main1(String[] args) throws CloneNotSupportedException{
        //这是“只有一层”的克隆——如果拷贝的东西中没有别的东西可以这样写（比如student在这时还没有score这个对象）
        Student student1 = new Student();
        student1.name = "小狗";
        Student student2 = (Student) student1.clone();
        System.out.println(student1.name);
        System.out.println(student2.name);
        System.out.println("================");
        student2.name = "小猫";
        System.out.println(student1.name);
        System.out.println(student2.name);

    }
}
